package com.java.datastructures;

/**
 * 线性查找
 * 从头到尾查找一遍
 * @author wangning
 * @create 2021-05-19 21:54
 */
public class TestSearch01 {
	public static void main(String[] args) {
		//目标数组
		int[] arr = new int[]{2, 3, 5, 6, 8, 9, 0};
		//目标元素
		int target = 4;
		//目标元素所在的下标
		int index = -1;
		//遍历数组
		for (int i = 0; i < arr.length; i++) {
			if(arr[i] == target) {
				index = i;
				break;
			}
		}
		//打印目标元素的下标
		System.out.println(index);

	}
}
